<template>
	<view>
		
	
			<view style="width: 100%; height: 50px; font-size: 17px; font-weight: bold; text-align: center; line-height: 50px;">我发布的</view>			
			<view class="goodlist_item" v-for="(item, i) in postlist" :key="i">
				<view class="left">
					<image :src="item.pictures[0]" style="width: 100px;"></image>
				</view>
				<view class="right">
					<view style="font-weight: bold; font-size: 18px;">{{item.name}}</view>
					
					<view style="font-size: 12px;">发布时间：{{item.date.slice(0, 23)}}</view>
				
					<view style="display: flex; margin-bottom: 2px;">
						<button class="change_Product" @click="change_item(item)">修改</button>
						<button class="change_Product" @click="delete_id(item._id)">删除</button>
					</view>
				</view>
			</view>	
						

	</view>
</template>

<script>
	import { mapState, mapMutations, mapGetters } from 'vuex'
	
	export default {
		data() {
			return {
				postlist: [],
			};
		},
		onLoad() {
			this.cha()
			console.log(this.postlist)
			
		},
		computed: {
			...mapState('m_my', ['user_id']),
		},
		methods: {
			
			async cha(){
				const db = uniCloud.database();
				//用await保证函数彻底执行完，数据返回完毕后再执行下面的代码,limit(1),取第一条数据，get(),执行查询操作
				this.res = await db.collection("category").get();
			
				//获得的数据藏在res.result.data里，取值就行了
				this.postlist = this.res.result.data.filter(x => x.openid === this.user_id) 
				
			},
			
			delete_id(id) {
				const db = uniCloud.database();
				db.collection("category").doc(id).remove()
				this.cha()
				
				//清除category中的数据
			},
			change_item(goods) {
				console.log(JSON.stringify(goods))
				uni.navigateTo({
					url: '/subpkg/change_post/change_post?goods=' + JSON.stringify(goods)
				})
			}
		}
	}
</script>

<style lang="scss">
	
	.goodlist_item {
		height: 100px;
		border: 1px solid #efefef;
		display: flex;
	}
	.left {
		height: 100px;
	}
	.left image {
		height: 100%;
	}
	
	.right {
		margin-left: 5px;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		width: 100%;
	}
	
	.change_Product {
		background-color: #84AF9B;
		height: 32px;
		font-size: 13px;
		color: white;

	}

</style>
